package com.coffee.mapper;

import com.coffee.annotation.AutoFill;
import com.coffee.dto.CategoryPageQueryDTO;
import com.coffee.entity.Category;
import com.coffee.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 新增分类
     * @param category
     */
    @Insert("insert into category (type, name, sort, status, create_time, update_time, create_user, update_user)" +
            "values"+" (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @AutoFill(OperationType.INSERT)
    void insert(Category category);

    /**
     * 分类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 更新category
     * @param category
     */
    @AutoFill(OperationType.UPDATE)
    void update(Category category);

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    //@Select("select * from category where type=#{type}")
    List<Category> getByType(Integer type);

    @Delete("delete from category where id=#{id}")
    void deleteById(long id);

    /**
     * 通过类型id查询类型名称
     * @param categoryId
     * @return
     */
    @Select("select name from category where id=#{categoryId}")
    String getNameByCategpryid(Long categoryId);
}
